﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LeadVinaglue.Models.ViewPages;
using LeadVinaglue.Models;

namespace LeadVinaglue.Areas.Management.Controllers
{
    public class SystemSettingsController : Controller
    {
        // Create an instance of user manage
        LeadVinaglue.Repository.SystemSettingManagementRepository repository = new LeadVinaglue.Repository.SystemSettingManagementRepository();

        //
        // GET: /Management/StateList/
        [Authorize(Roles = "SuperAdministrator")]
        public ActionResult Index()
        {
            SystemSettingManagementModel model = new SystemSettingManagementModel();
            string filePath = Server.MapPath(@"/Configs/WebsiteSettingConfig.xml");
            model = repository.GetModel(Helpers.Constant.HOME, "SuperAdministrator", filePath);

            return View(model);
        }

        [HttpGet]
        [Authorize(Roles = "SuperAdministrator")]
        public ActionResult Synchronize(string type)
        {
            NavigationConfig config = new NavigationConfig();
            string filePath = string.Empty;
            bool success=true;

            filePath = Server.MapPath(@"/Configs/CategoryListConfig.xml");
            repository.GenerateXMLFromCategory(filePath, ref success);
            
            return Json("Success", JsonRequestBehavior.AllowGet); 
        }
    }
}
